package com.thread.practice;

public class CurrentThreadDemo {
	// 控制main线程
	public static void main(String[] args) {
		Thread t = Thread.currentThread();
		System.out.println("CurrentThread:" + t);
		t.setName("My Thread");
		System.out.println("After name change:" + t);
		for (int i = 5; i > 0; i--) {
			System.out.println(i);
			try {
				Thread.sleep(1000);//一秒 这里1000为毫秒  sleep方法使线程从调用时挂起，暂缓执行指定的时间间隔
			} catch (InterruptedException e) {
				// 如果其他线程试图中断这个正在睡眠的线程，就会发生这种情况
				// TODO Auto-generated catch block
				System.out.println("Main thread interrupted");
			}
		}

	}

}
